package com.huonan.component.es;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.dialect.PropsUtil;

public class EsExportApp {
    /**
     * 导数参数配置文件，当前目录下的 es_config.txt
     * 默认配置
     * isSingleIndex: 是否索引全名 false
     * isThread：是否多线程 false
     * dateType 索引类型 month
     * 必填配置
     * dsl ：dsl 语句
     * path: 导出文件路径，全路径
     * platform: 平台，也可以是索引全名
     */
    public static final String SQL_FILE = baseDir() + "/es_config.txt";

    private static String baseDir() {
        return System.getProperty("user.dir");
    }

    public static void main(String[] args) throws InterruptedException {
        Props props1 = PropsUtil.get(SQL_FILE);
        String oldDsl = props1.getStr("dsl");
        String dsl = CharsetUtil.convert(oldDsl, CharsetUtil.ISO_8859_1, CharsetUtil.UTF_8);
        String outPath = props1.getStr("path");
        String platform = props1.getStr("platform");
        boolean isSingleIndex = props1.getBool("isSingleIndex", false);
        boolean isThread = props1.getBool("isThread", false);
        String dateType = props1.getStr("dateType", "month");
        String dataRange = props1.getStr("dataRange", "30");//数据范围，默认30个月
        IndexDateType indexDateType;
        if (dateType.equals(IndexDateType.DAY_TYPE.getName())) {
            indexDateType = IndexDateType.DAY_TYPE;
        } else {
            indexDateType = IndexDateType.MOTH_TYPE;
        }
        ESComponent.searchWithThread(outPath, platform, dsl, indexDateType, isThread, isSingleIndex);

    }
}
